﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using Microsoft.Win32;


namespace Library
{
    [RunInstaller(true)]
    public partial class InstallerIntelliPaper : System.Configuration.Install.Installer
    {
        public InstallerIntelliPaper()
        {
            InitializeComponent();
            this.AfterInstall += new InstallEventHandler(InstallerIntelliPaper_AfterInstall);
        }

        void InstallerIntelliPaper_AfterInstall(object sender, InstallEventArgs e)
        {
            try
            {
                RegistryKey key = Registry.ClassesRoot;

                RegistryKey mpd = key.CreateSubKey(".mpd");

                mpd.SetValue(null, "mpdfile");

                RegistryKey mpdfile = key.CreateSubKey("mpdfile");

                RegistryKey shell = mpdfile.CreateSubKey("shell");
                RegistryKey defaulticon = mpdfile.CreateSubKey("DefaultIcon");

                RegistryKey open = shell.CreateSubKey("open");

                RegistryKey command = open.CreateSubKey("command");

                string appdirectory = this.Context.Parameters["targetdir"];

                defaulticon.SetValue(null, appdirectory.Remove(appdirectory.Length - 1) + "intelliPaper.Regedit.exe");

                command.SetValue(null, appdirectory.Remove (appdirectory.Length -1)+"intelliPaper.Regedit.exe \"%1\"");

                key.Close();



            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
            //throw new NotImplementedException();
        }
    }
}
